package com.why.blog.front.tag.api;

import com.why.blog.common.ResponseCode;
import com.why.blog.entity.VO.TagVo;
import com.why.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author TriggerWu
 * @version 1.0.0
 * @ClassName TagControllerApi.java
 * @Description 查询标签信息
 * @createTime 2019年06月01日 16:48:00
 */
@RestController
@RequestMapping("/tag/api")
public class TagControllerApi {
    @Autowired
    private TagService tagService;

    @GetMapping("/selecttags")
    public Map<String, Object> selectTags(@RequestParam("postId") String postId) {
        Map<String, Object> map = new HashMap<>();
        List<TagVo> tagslist = tagService.selectTags(postId);
        if (tagslist != null || tagslist.size() != 0) {
            map.put("tagList", tagslist);
            return map;
        }
        map.put(ResponseCode.ARG_ERROR.getCode(), ResponseCode.ARG_ERROR.getMsg());
        return map;
    }

    @GetMapping("/tagCloud")
    public Map<String, Object> tagClouds() {
        Map<String, Object> map = new HashMap<>();
        List<TagVo> tagVoList = tagService.tagCloud();
        if (tagVoList != null || tagVoList.size() != 0) {
            map.put("status",ResponseCode.RESPONSE_SUCCESS.getCode());
            map.put("tagList", tagVoList);
            return map;
        }
        map.put(ResponseCode.ARG_ERROR.getCode(), ResponseCode.ARG_ERROR.getMsg());
        return map;
    }


}
